<template>
  <div>
    <el-card>
      <div slot="header" class="header">
        <div class="category-header">
          <span>销售额类别占比</span>
          <el-radio-group v-model="radio" size="medium">
            <el-radio-button label="全部渠道"></el-radio-button>
            <el-radio-button label="线上"></el-radio-button>
            <el-radio-button label="门店"></el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div>
        <div class="charts" ref="charts"></div>
      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  data() {
    return {
      radio: "全部渠道",
    };
  },
  mounted() {
    let pieCharts = echarts.init(this.$refs.charts);
    pieCharts.setOption({
      title: {
          text: '',
          subtext: '',
          left: 'center',
          top: 'center'  
      },  
      tooltip: {
        trigger: "item",
      },
      legend: {
        left: "center",
      },
      series: [
        {
          name: "Access From",
          type: "pie",
          radius: ["40%", "70%"],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: "#fff",
            borderWidth: 2,
          },
          label: {
            show: true,
            position: "outside",
          },
          labelLine: {
            show: true,
          },
          data: [
            { value: 1048, name: "视频广告" },
            { value: 735, name: "搜索引擎" },
            { value: 580, name: "直接访问" },
            { value: 484, name: "邮件营销" },
            { value: 300, name: "联盟广告" },
          ]
        },
      ],
    });
    pieCharts.on('mouseover', (params) => {
        const {name, value} = params;
        pieCharts.setOption({
            title: {
                text: name,
                subtext: value
            }
        })
    })
  },
};
</script>

<style scoped>
.charts {
  width: 100%;
  height: 400px;
}
.header {
  padding-bottom: 5px;
  border-bottom: 1px solid #eee;
}
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
